const BASE_URL = 'https://api.huhuiyu.top';

//#region 邮箱验证码演示

let txt_email = document.getElementById('txt_email');
let btnSendEmail = document.getElementById('btnSendEmail');

btnSendEmail.addEventListener('click', () => {
  let info = {
    email: txt_email.value,
    code: '',
  };

  let promise = axios({
    url: BASE_URL + '/tools/sendMailCode',
    method: 'post',
    data: info,
  });

  promise
    .then((resp) => {
      alert(resp.data.message);
    })
    .catch((err) => {
      console.error(err);
    });
});

//#endregion

//#region 获取ip地址相关信息

let divIp = document.getElementById('divIp');
function queryIp() {
  let promise = axios({
    url: BASE_URL + '/tools/ipinfo',
    method: 'get',
    data: '',
  });
  promise
    .then((resp) => {
      let info = resp.data.data;
      //divIp.innerHTML = JSON.stringify(info);
      divIp.innerHTML = `${info.province}${info.city}`;
    })
    .catch((err) => {
      console.error(err);
    });
}

queryIp();

//#endregion
